using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class ColorUtil 
{
    public static Color TryParse(string text, Color? _default = null)
    {
        var b = ColorUtility.TryParseHtmlString(text, out var color);
        if(b)
        {
            return color;
        }
        else
        {
            Debug.Log($"parse color {text} faild");
            if (_default == null)
            {
                return Color.white;
            }
            else
            {
                return _default.Value;
            }
        }
    }

    public static string AddTag(string text, string colorCode)
    {
        var ret = $"<color={colorCode}>{text}</color>";
        return ret;
    }

    public static string AddRedTag(string text)
    {
        var code = "#fff25c";
        return AddTag(text, code);
    }

    public static string AddGreenTag(string text)
    {
        var code = "#00ff00";
        return AddTag(text, code);
    }
}
